/**
 * 
 */
package pizza.admin.entity;

import static javax.persistence.GenerationType.IDENTITY;

import java.math.BigDecimal;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import pizza.admin.helper.HtmlHelper;

/**
 * @author Joro
 * @version 1.0
 */

@Entity
@Table(name = "Pizza")
public class Pizza {
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = true)
	private Integer id;

	@Column(name = "name", unique = false, nullable = false)
	private String name;

	@Column(name = "description", unique = false, nullable = false)
	private String description;

	@Column(name = "price", unique = false, nullable = false, precision = 10, scale = 2)
	private Double price;
	
	@OneToMany(cascade= CascadeType.REMOVE, mappedBy="pizza", fetch = FetchType.LAZY)
    private Collection<OrderPizza> orederPizas;
	
	public Pizza() {
		super();
		id = null;
		name = "";
		description = "";
		price = 0.00;
		
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}

	public Boolean validateForDB() {

		// validate before add
		if (name.isEmpty() || description.isEmpty() || price <= 0) {
			return false;
		}
		return true;

	}

	public void purifyFields() {
		HtmlHelper helper = new HtmlHelper();
		name = helper.purify(name);
		description = helper.purify(description);

	}

}
